package com.wfm.queues;

import java.util.concurrent.PriorityBlockingQueue;

public class PriorityBlockingQueueExample {
    public static void main(String[] args) throws InterruptedException {
        PriorityBlockingQueue<Integer> queue = new PriorityBlockingQueue<>();

        // 生产者线程
        Thread producer = new Thread(() -> {
            queue.put(5);
            queue.put(1);
            queue.put(3);
            System.out.println("生产者放入完成");
        });

        // 消费者线程
        Thread consumer = new Thread(() -> {
            try {
                while (!queue.isEmpty()) {
                    System.out.println("消费者取出: " + queue.take());
                }
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        });

        producer.start();
        consumer.start();

        producer.join();
        consumer.join();
    }
}